<?php
namespace API\Controller;
use Think\Controller;
/**
* 注册业务
*/
class RegController extends PublicController
{
	/**
	 * 注册
	 * @return [type] [description]
	 */
	public function reguser(){
		if (IS_POST) {
			$data['uname'] = $_POST['uname'];
			$data['pwd']   = $this -> HdEncrypt($_POST['pwd']);
			$data['utel']  = $_POST['utel'];
		}
		elseif(IS_GET){
            $data['uname'] = $_GET['uname'];
			$data['pwd']   = $this -> HdEncrypt($_GET['pwd']);
			$data['utel']  = $_GET['utel'];
		}
		if(!empty($data['uname'])&&!empty($data['pwd'])&&!empty($data['utel'])){
			  $data['regtime'] = array('exp','now()');
              $m = M("Users");
              if (false!=$m->add($data)) {
              	return PublicController::codedate(1,"success");
              }else{
                 return PublicController::codedate(0,"fail");	
              }
		}else{
			return PublicController::codedate(403,"");
		}
	}
	/**
	 * 用户名是否可用
	 * @return [type] [description]
	 */
	public function viewrep(){
		if (IS_POST) {
			$data['uname'] = $_POST['uname'];
		}
		elseif(IS_GET){
            $data['uname'] = $_GET['uname'];
		}
		if (!empty($data['uname'])) {
			$m = M("Users");
			$result = $m -> where($data) -> count();
			if($result){
             $sentdate = array('success'=>'1');//不可用
             echo json_encode($sentdate);
			}else{
			$sentdate = array('success'=>'0');//可用
			 echo json_encode($sentdate);
			}
		}else{
			return PublicController::codedate(403,"");
		}
	}
}